<template>
  <el-select
    v-model="current_field"
    clearable
    :placeholder="$util.getDefValue(current_args.placeholder, '请选择')"
    :collapse-tags="collapseTagsValue"
    :multiple="multipleValue"
    :multiple-limit="$util.getDefValue(current_args.max, 0)"
    :disabled="disabledValue"
    @change="$emit('update:value', current_field)"
  >
    <el-option v-for="option in selectOptions" :key="option.value" :value="option.value" :label="option.title" />
  </el-select>
</template>
<script>
export default {
  props: {
    value: {
      type: String,
      default: ''
    },
    args: {
      type: Object,
      required: true,
      default: _ => {
        return {};
      }
    },
    options: {
      type: Array,
      default: _ => {
        return [];
      }
    }
  },
  data() {
    return {
      current_field: this.value,
      current_args: this.args
    };
  },
  computed: {
    disabledValue() {
      if (this.current_args.disabled == '1') {
        return true;
      }

      return null;
    },
    collapseTagsValue() {
      if (this.current_args.megre_tags == '1') {
        return true;
      }

      return null;
    },
    multipleValue() {
      if (this.current_args.multiple == '1') {
        return true;
      }

      return null;
    },
    selectOptions() {
      if (this.$util.isArray(this.options) && this.options.length > 0) {
        return this.options;
      }
      return [];
    }
  },
  watch: {
    value: {
      handler(now, old) {
        this.current_field = now;
      }
    }
  }
};
</script>
